package code._13io.bytestream.copy;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo {
    public static void main(String[] args) throws IOException {
        FileInputStream in = new FileInputStream("fileTest\\a.txt");
        FileOutputStream out = new FileOutputStream("fileTest\\b.txt");
        long start = System.currentTimeMillis();
        copyMulti(in,out);
        //copySingle(in,out);
        long end = System.currentTimeMillis();
        System.out.println("(end-start) = " + (end-start));
        in.close();
        out.close();


    }

    private static void copyMulti(FileInputStream in,FileOutputStream out)throws IOException{
        byte[] bytes = new byte[1024];
        int readCount;
        while((readCount=in.read(bytes))!=-1){
            out.write(bytes,0,readCount);
        }
    }

    private static void copySingle(FileInputStream in,FileOutputStream out)throws IOException{

        int readData;
        while((readData=in.read())!=-1){
            out.write(readData);
        }
    }
}
